﻿@inject IStringLocalizer<TablesFixedHeaderDialog> Localizer
@inject IStringLocalizer<Foo> FooLocalizer
@inject DialogService DialogService

<style>
    .dialog-table .modal-body {
        height: calc(100vh - 400px);
        overflow: hidden;
    }
</style>

<Button Text="@Localizer["DialogButtonText"]" OnClick="OnClickDialog" class="mt-3"></Button>

@code {
    [NotNull]
    private List<Foo>? Items { get; set; }

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        base.OnInitialized();

        Items = Foo.GenerateFoo(FooLocalizer);
    }

    private async Task OnClickDialog()
    {
        var op = new DialogOption
                {
                    Class = "dialog-table",
                    Title = Localizer["DialogTitle"],
                    BodyTemplate = RenderTable()
                };

        await DialogService.Show(op);
    }

    RenderFragment RenderTable() =>
    @<Table TItem="Foo" Items="@Items" ShowColumnList="true" ShowToolbar="true" ShowDefaultButtons="false" ShowRefresh="false"
       IsBordered="true" IsMultipleSelect="true" IsPagination="true" IsFixedHeader="true" AllowResizing="true" RenderMode="TableRenderMode.Table">
        <TableColumns>
            <TableColumn @bind-Field="@context.DateTime" Width="180" />
            <TableColumn @bind-Field="@context.Name" Width="100" />
            <TableColumn @bind-Field="@context.Address" Width="900" />
        </TableColumns>
    </Table>;
}
